package com.xwaiy.xwaiyrpc.exception.enums;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.ToString;

/**
 * RPC错误码枚举
 * @Author Xwaiy
 * @Date 2025/9/3
 */
@Getter
@ToString
public enum ErrorCode {

    // 消费者异常 (1000-1999)
    CONSUMER_SERVICE_NOT_FOUND(1001, "服务未找到", "消费者异常"),
    CONSUMER_SERVICE_UNAVAILABLE(1002, "服务不可用", "消费者异常"),
    CONSUMER_INVOCATION_FAILED(1003, "服务调用失败", "消费者异常"),
    CONSUMER_TIMEOUT(1004, "服务调用超时", "消费者异常"),
    CONSUMER_NETWORK_ERROR(1005, "网络通信异常", "消费者异常"),

    // 提供者异常 (2000-2999)
    PROVIDER_SERVICE_NOT_IMPLEMENTED(2001, "服务未实现", "提供者异常"),
    PROVIDER_SERVICE_EXECUTION_ERROR(2002, "服务执行异常", "提供者异常"),
    PROVIDER_SERIALIZATION_ERROR(2003, "序列化异常", "提供者异常"),
    PROVIDER_DESERIALIZATION_ERROR(2004, "反序列化异常", "提供者异常"),
    PROVIDER_METHOD_NOT_FOUND(2005, "方法未找到", "提供者异常"),

    // 注册中心异常 (3000-3999)
    REGISTRY_CONNECTION_FAILED(3001, "注册中心连接失败", "注册中心异常"),
    REGISTRY_SERVICE_REGISTER_FAILED(3002, "服务注册失败", "注册中心异常"),
    REGISTRY_SERVICE_UNREGISTER_FAILED(3003, "服务注销失败", "注册中心异常"),
    REGISTRY_SERVICE_DISCOVERY_FAILED(3004, "服务发现失败", "注册中心异常"),
    REGISTRY_HEARTBEAT_FAILED(3005, "心跳检测失败", "注册中心异常"),

    // 配置异常 (4000-4999)
    CONFIG_LOAD_FAILED(4001, "配置加载失败", "配置异常"),
    CONFIG_VALIDATION_FAILED(4002, "配置验证失败", "配置异常"),
    CONFIG_MISSING_REQUIRED(4003, "缺少必要配置", "配置异常"),

    // 协议异常 (5000-5999)
    PROTOCOL_ENCODE_FAILED(5001, "协议编码失败", "协议异常"),
    PROTOCOL_DECODE_FAILED(5002, "协议解码失败", "协议异常"),
    PROTOCOL_VERSION_MISMATCH(5003, "协议版本不匹配", "协议异常"),
    PROTOCOL_INVALID_MESSAGE(5004, "无效协议消息", "协议异常"),

    // 系统异常 (9000-9999)
    SYSTEM_ERROR(9001, "系统内部错误", "系统异常"),
    SYSTEM_BUSY(9002, "系统繁忙", "系统异常"),
    SYSTEM_RESOURCE_EXHAUSTED(9003, "系统资源耗尽", "系统异常");

    private final int code;
    private final String message;
    private final String category;

    ErrorCode(int code, String message, String category) {
        this.code = code;
        this.message = message;
        this.category = category;
    }

}